import React, { useState, useEffect } from "react"
import marked from 'marked';
import service from "@@/services/data.service"
import { activityIntro } from "@@/interfaces/api.interface"
import { BaseEventOrig, Image, Picker, Text, View, RichText } from "@tarojs/components"
import {
    useDidHide,
    useDidShow,
    usePageScroll,
    usePullDownRefresh,
    useReachBottom,
    useReady,
    useResize,
    useTabItemTap,
    navigateTo,
    pageScrollTo,
    Current,
    getSystemInfoSync
} from "@tarojs/taro"
import NavLayout from "@@/components/layout/nav.layout"
import TBread from "@@/t-ui/bread.tui"
import ProxyConfig from "@@/../config/proxy"
import "./newDetail.scss"

type breadType = {
    name: string | undefined
}

const Index = () => {
    const [newDetail, setNewDetail] = useState<activityIntro>()//
    const [breadList, setBreadList] = useState<breadType[]>([])
    useDidShow(() => {
        pageScrollTo({
            selector: "#newDetail",
            scrollTop: 1 - 100,
        })
    })
    useEffect(() => {
        setBreadList([
            { name: "新闻资讯" },
            { name: "资讯详情" },
        ])
        let id = Number(Current.router?.params?.id)
        // 暂用 新闻资讯列表
        service.getNew({ id, pageSize: 1, currentPage: 1 }).then(rslt => {
            // console.log(rslt.data.entities)
            // rslt.data.entities[0].content = rslt.data.entities[0].content.replace(/\"><img/gi, 'height:200px;"><img')
            // rslt.data.entities[0].content = rslt.data.entities[0].content.replace(/\alt="image.png">& nbsp;/gi, 'alt="image.png">')
            setNewDetail(rslt.data.entities[0])
        })
    }, [])
    return (
        <NavLayout border leftIconType="chevron-left" color="#141414" id="newDetail">
            <TBread breadList={breadList} />
            {
                newDetail && <View className={"context_box"}>
                    <View className={"title"}>{newDetail.title}</View>
                    {/* <RichText className={"text"} nodes={newDetail?.content}></RichText> */}
                    <RichText className={"text"} nodes={marked(newDetail?.content).replace(/<img/g, "<img class='markimg'")}></RichText>
                    {/* <View className={"text"} dangerouslySetInnerHTML={{ __html: newDetail?.content }}></View> */}
                    <View className={'img_box'}><Image src={`${ProxyConfig.sourceUrl}/${newDetail?.image}`} /></View>
                </View>
            }
            {/* <View className={"context_box"}>
                <View className={"title"}>智慧先行，未来已来 | 大华股份入选浙江省首批“未来工厂”</View>
                <View className={"text"} dangerouslySetInnerHTML={{ __html: testHtml }}></View>
                <View className={'img_box'}><Image src={`${ProxyConfig.sourceUrl}/8c60f646ee984d41b30ae7f20bbd93bf.png`} /></View>
            </View> */}
            <View className={"copyright_box"}>
                <View className={"copyright"}>
                    <View>版权所有 © 浙江大华技术股份有限公司 1998-2021。 </View>
                    <View>保留一切权利。备案号A4-254545477号</View>
                </View>
            </View>
        </NavLayout>
    )
}

export default Index